<?php 
include "includes/session.php";
include "includes/comunes.php";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sistema de Gestion de Vehiculos</title>

<link href="estilos.css" rel="stylesheet" type="text/css" />

<!--libreria jquery central-->
<script src="jquery-ui/js/jquery-1.9.1.js"></script>
<!--fin libreria central-->

<!--Librerias para el combo-->
<script language="JavaScript" type="text/javascript" src="combos/jquery.chainedSelects.js"></script>
<!--fin libreria-->

<!--librerias ui-->
<link href="jquery-ui/css/ui-lightness/jquery-ui-1.10.2.custom.css" rel="stylesheet"/>
<script src="jquery-ui/js/jquery-ui-1.10.2.custom.js"></script>
<!--fin libreria-->
<!--estilo para el scroll-->
<style>
  .ui-autocomplete {
    max-height: 300px;
    overflow-y: auto;
    /* prevent horizontal scrollbar */
    overflow-x: hidden;
  }
  /* IE 6 doesn't support max-height
   * we use height instead, but this forces the menu to always be this tall
   */
  * html .ui-autocomplete {
    height: 300px;
  }
  </style>
<!--
  fin estilo scroll-->


<script language="JavaScript" type="text/javascript">
$(function()
{

//        funcion que implementa combos

$('#categoria').chainSelect('#marca','combomarcamarca.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});


	$('#marca').chainSelect('#modelo','combomarcamodelo.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
        $('#modelo').chainSelect('#version','combomodeloversion.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
        
           $('#venpro').chainSelect('#venloc','comboprolocalidad.php',
	{
		before:function (target) //before request hide the target combobox and display the loading message
		{
			$("#loading").css("display","block");
			$(target).css("display","none");
		},
		after:function (target) //after request show the target combobox and hide the loading message
		{
			$("#loading").css("display","none");
			$(target).css("display","inline");
		}
	});
        
//        fin funcion

// busco datos en caso de que existA

$("#imgbus").click(function(evento){
      evento.preventDefault();
      $("#vendedor").load("datosVendedor.php", {dni: $("#vendni").val()});
   });
   
   
  $("#imgbusnombre").click(function(evento){
      evento.preventDefault();
      $("#vendedor").load("datosVendedorNombre.php", {dni: $("#venape").val()});
   }); 
   




//          funcion que implementa autocompletado de articulos
     
// $( "#fechapla" ).datepicker({
//         dateFormat: "yy-mm-dd"
//
//      });


		
		$( "#vendni" ).autocomplete({
			source: "autoPersona.php"
		});
		
		$( "#comprador" ).autocomplete({
			source: "autoPersonaNombre.php"
		});
                
                $( "#accdni" ).autocomplete({
			source: "autoAccionista.php"
		});
                $( "#accdni1" ).autocomplete({
			source: "autoAccionista.php"
		});
                $( "#accdni2" ).autocomplete({
			source: "autoAccionista.php"
		});
                   $( "#accdni3" ).autocomplete({
			source: "autoAccionista.php"
		});
             
			  $( "#venape" ).autocomplete({
			source: "autoPersonaNombre.php"
		});

//          fin funcion



//              funcion para validacion de formularios

             $("#altavehiculo").submit(function () {

                  if (confirm('Esta seguro que confirma el pedido?')){ 
					   return true;
					}else
					   return false;
                    
               
        });

//              fin funcion
      $("#accpor").change(function(){
               
                        var1=($("#accpor").val())/100;
						if ($("#contipo").val()==2){
						 var2=$("#preciocosto").val() -$("#preciocosto").val() ;}
						else{
                        var2=$("#preciocosto").val();}
						
                        monto=var1*var2;
                       
                       $("#accmon").val(monto); 
                         

             });
             
          $("#accpor1").change(function(){
               
                        var1=($("#accpor1").val())/100;
                        if ($("#contipo").val()==2){
						 var2=$("#preciocosto").val() -$("#preciocosto").val() ;}
						else{
                        var2=$("#preciocosto").val();}
                        monto=var1*var2;
                       
                       $("#accmon1").val(monto); 
                         

             });   
             
             $("#accpor2").change(function(){
               
                        var1=($("#accpor2").val())/100;
                        if ($("#contipo").val()==2){
						 var2=$("#preciocosto").val() -$("#preciocosto").val() ;}
						else{
                        var2=$("#preciocosto").val();}
                        monto=var1*var2;
                       
                       $("#accmon2").val(monto); 
                         

             });
			 
			 $("#accpor3").change(function(){
               
                        var1=($("#accpor3").val())/100;
                         if ($("#contipo").val()==2){
						 var2=$("#preciocosto").val() -$("#preciocosto").val() ;}
						else{
                        var2=$("#preciocosto").val();}
                        monto=var1*var2;
                       
                       $("#accmon3").val(monto); 
                         

             });
             //calculo el total
			 $(document).on("change","#accpor",function(){
                         importe_total = Number($("#accmon3").val()) + Number($("#accmon2").val())+ Number($("#accmon1").val())+ Number($("#accmon").val());
						 var total =importe_total;
						 $("#total").html('<b>$ '+total+'</b>');
						
             });
			 $(document).on("change","#accpor1",function(){
                         importe_total = Number($("#accmon3").val()) + Number($("#accmon2").val())+ Number($("#accmon1").val())+ Number($("#accmon").val());
						 var total =importe_total;
						 $("#total").html('<b>$ '+total+'</b>');
						
             });
			 $(document).on("change","#accpor2",function(){
                         importe_total = Number($("#accmon3").val()) + Number($("#accmon2").val())+ Number($("#accmon1").val())+ Number($("#accmon").val());
						 var total =importe_total;
						 $("#total").html('<b>$ '+total+'</b>');
						
             });
			 $(document).on("change","#accpor3",function(){
                         importe_total = Number($("#accmon3").val()) + Number($("#accmon2").val())+ Number($("#accmon1").val())+ Number($("#accmon").val());
						 var total =importe_total;
						 $("#total").html('<b>$ '+total+'</b>');
						
             });
             
             
             //calculo el porcentaje de venta en caso de ser necesario
              $("#por").change(function(){
               
                        var1=($("#por").val())/100;
                        var2=$("#preciocosto").val();
                        monto=(parseFloat(var1*var2)+parseFloat(var2));
                      
                       
                       $("#precioventa").val(monto); 
                         

             });
			 
			  $("#preciotoma").change(function(){
                      monto=$("#preciotoma").val();
                      $("#preciocosto").val(monto); 
                         

             });
             
$("#pedido").submit(function () {

valor_vehiculo=Number($("#preciocosto").val());
importe_total= Number($("#accmon3").val()) + Number($("#accmon2").val())+ Number($("#accmon1").val())+ Number($("#accmon").val());

dif=   valor_vehiculo -  importe_total ;
         if(dif <= 0)
                  if (confirm('Esta seguro que confirma los datos cargados?')){ 
					   return true;
					}else
					   return false;
		else{
           alert('Los valores ingresos son menores al valor del vehiculo');
           return false;	}
 
                  
});

});
</script>
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
</head>

<body>

<div class="container">
<?php include "includes/head.php"?>
   <div class="content">
       <div class="tituloprincipal">
          <?php include 'includes/submenu.php';?>  
           <img src="img/nuevo.png" width="25" height="25" border="0"/> Nuevo Contrato de Compra (Alta de Vehiculo)
           </div>
       <form id="pedido" name="pedido" method="POST" action="grabarBoletoCompra.php">
       <div class="contenedorpedido">
	   <fieldset>
              <legend><b>Tipo de Contrato</b></legend> 
	   <table  width="100%">
                 <tr>
                      <td class="textotablamenuform">Tipo</td>
                      <td class="textotablamenuform">
                          <select name="contipo" id="contipo" class="campo_form" required>
                              <option value='1'>Compra de Vehiculo</option>
                              <option value='2'>Consignacion</option>
                         </select>
                      </td>
					  </table>
			</fieldset>		  
	   
        <fieldset>
              <legend><b>Datos del Comprador</b></legend> 
	   <table  width="100%">
                 <tr>
                      <td class="textotablamenuform">Comprador</td>
                      <td class="textotablamenuform">
                          <input name="comprador" type="text" id="comprador" class="campo_form" required />
                      </td>
					  </table>
			</fieldset>	
       
       
           <div id="vendedor">
           <fieldset>
              <legend><b>Datos del Vendedor</b></legend> 
               <table  width="100%">
                 <tr>
				<input type="hidden" class="campo_form"  id="usualta" name="usualta" value="1">
                      <td class="textotablamenuform">Tipo</td>
                      <td class="textotablamenuform">
                          <select name="ventipo" id="ventipo" class="campo_form" required>
                              <option value='1'>Persona Fisica</option>
                              <option value='2'>Persona Juridica</option>
                         </select>
                      </td>
                      <td class="textotablamenuform">Dni/Cuit</td>
                      <td class="textotablamenuform">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 28992993" id="vendni" name="vendni" required style="width:80%;">
                           <img src="img/actualizar.jpg" width="20" id="imgbus" style="margin-top:15px;"/>
                      </td>
                      
                 </tr>
                   <tr>
                      <td class="textotablamenuform">Nombre y Apellido</td>
                      <td class="textotablamenuform" colspan="5">
                           <input type="text" class="campo_form"  style="width:80%;" id="venape" name="venape" required>
						   <img src="img/actualizar.jpg" width="20" id="imgbusnombre" style="margin-top:15px;"/>
                               
                      </td> 
                   </tr>
                   
                   <tr>
                      <td class="textotablamenuform">Telefono Fijo</td>
                      <td class="textotablamenuform">
                          <input type="number" class="campo_form" placeholder="Ej. 03624 764244" id="ventelf" name="ventelf">
                    
                      </td>
                      <td class="textotablamenuform">Telefono Celular</td>
                      <td class="textotablamenuform">
                          <input type="number" class="campo_form" placeholder="Ej. 0362 154764244" id="ventelc" name="ventelc">
                    
                      </td>
                      
                 </tr>
                   <tr>
                      
                      <td class="textotablamenuform">Direccion</td>
                      <td class="textotablamenuform" colspan="2">
                           <input type="text" class="campo_form"  id="venape" name="vendir" required>
                    
                      </td>
                       <td class="textotablamenuform">
                         <select name="venpro" id="venpro" class="campo_form" required>
                             
                             <?php
                             $cat=obtener_provincias();

                             while($regPed=mysql_fetch_array($cat)){
                                 echo "<option value='".utf8_encode($regPed['id_provincia'])."'>".utf8_encode($regPed['nombre'])."</option>";
                             }

                             ?>

                         </select>


                     </td>
                       <td class="textotablamenuform" colspan="3">
                         <select name="venloc" id="venloc" class="campo_form" required style="display:none">
                            

                         </select>


                     </td>
                 </tr>
                   
                   
                   
               </table>    
           </fieldset>  
           </div>
           
        <fieldset>
             <legend><b>Datos del Vehiculo</b></legend>
             <table>
                 <tr>
                     <td class="textotablamenuform">Categoria</td>
                     <td class="textotablamenuform">
                         <select name="categoria" id="categoria" class="campo_form" required>
                             <option selected value="0">Seleccionar...</option>
                             <?php
                             $cat=obtener_categorias();

                             while($regPed=mysql_fetch_array($cat)){
                                 echo "<option value='".utf8_encode($regPed['idCategoria'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                             }

                             ?>

                         </select>


                     </td>
                     <td class="textotablamenuform">Marca</td>
                     <td class="textotablamenuform">
                         <select name="marca" id="marca" class="campo_form" required style="display:none">
                              <?php
                             $ped=obtener_marcas();

                             while($regPed=mysql_fetch_array($ped)){
                                       echo "<option value='".utf8_encode($regPed['id_marca'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                           

                             }

                             ?>

                         </select>


                     </td>
                     <td class="textotablamenuform">Modelo</td>
                     <td class="textotablamenuform">
                          <select name="modelo" id="modelo" class="campo_form" style="display:none" required>
                           
                            
                         </select>
                     </td>
                </tr>
                 <tr>
                     <td class="textotablamenuform">Version</td>
                     <td class="textotablamenuform">
                        <select name="version" id="version" class="campo_form" required style="display:none">
                             
                           

                         </select>
                     </td>
                     <td class="textotablamenuform">Año</td>
                     <td class="textotablamenuform">
                    <select name="ano" id="ano" class="campo_form" required>
                              <?php
                             $ped=obtener_anos();

                             while($regPed=mysql_fetch_array($ped)){
                                       echo "<option value='".utf8_encode($regPed['id_ano'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                           

                             }

                             ?>
                           

                         </select>
                     </td>
                     <td class="textotablamenuform">Color</td>
                     <td class="textotablamenuform">
                         
                        <select name="color" id="color" class="campo_form" required>
                              <?php
                             $ped=obtener_color();

                             while($regPed=mysql_fetch_array($ped)){
                                       echo "<option value='".utf8_encode($regPed['id_color'])."'>".utf8_encode($regPed['descripcion'])."</option>";
                           

                             }

                             ?>
                           

                         </select>
                     
                     
                     
                     </td>
                 </tr>
                 <tr>
                    <td class="textotablamenuform">Condicion</td>
                     <td class="textotablamenuform">
                         <select name="condicion" id="condicion" class="campo_form" required>
                              <option value='2'>Usado</option>
                              <option value='1'>0 km</option>
                         </select>
                         
                     </td>

                    <td class="textotablamenuform">Kilometros</td>
                    <td class="textotablamenuform">
                        <input type="text" class="campo_form" id="km" name="km" value="0">
                    </td>
                     <td class="textotablamenuform">Precio Toma</td>
                   <td class="textotablamenuform">
                        <input type="number" class="campo_form" placeholder="Ej. 123421,43" id="preciotoma" name="preciotoma" required>
                    </td>
                 </tr>
                  <tr>
                    <td class="textotablamenuform">Precio Costo</td>
                     <td class="textotablamenuform">
                            <input type="number" class="campo_form" placeholder="Ej. 123421,43" id="preciocosto" name="preciocosto" required>
                 
                         
                     </td>

                    
                       <td class="textotablamenuform">Precio Venta Estimado</td>
                     <td class="textotablamenuform">
                             <input type="number" class="campo_form" placeholder="Ej. 123421,43" id="precioventa" name="precioventa" required>
                 
                     </td>
                 </tr>
                   <tr>
                    <td class="textotablamenuform">Nro Chasis</td>
                     <td class="textotablamenuform" >
                            <input type="text" class="campo_form"  id="chasis" name="chasis" required>
                 
                         
                     </td>
                   <td class="textotablamenuform">Nro Motor</td>
                     <td class="textotablamenuform" >
                            <input type="text" class="campo_form"  id="motor" name="motor" required>
                 
                         
                     </td>
                   
                   <td class="textotablamenuform">Nro Patente</td>
                     <td class="textotablamenuform" >
                            <input type="text" class="campo_form"  id="patente" name="patente" maxlength="6" required>
                 
                         
                     </td>
                   
                 </tr>
                 
                 
                 <tr>
                    <td class="textotablamenuform">Caracteristicas</td>
                     <td class="textotablamenuform" colspan="5">
                            <input type="text" class="campo_form" placeholder="Ej. Cierre Centralizado, alarma, etc" id="carac" name="carac" >
                 
                         
                     </td>

                   
                 </tr>
                 
                 
             </table>
        </fieldset>
           
           <fieldset>
              <legend><b>Accionistas</b></legend> 
               <table  width="100%">
                 <tr>
                      <td class="textotablamenuform"  width="10%">Accionista 1</td>
                      <td class="textotablamenuform" colspan="2"  width="50%">
                          <input type="text" class="campo_form" autocomplete="on"  id="accdni" name="accdni" required style="width:80%;">
               
                      </td>
                      <td class="textotablamenuform" width="10%">%</td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 10" id="accpor" name="accpor"  style="width:80%;">
                          
                      </td>
                      <td class="textotablamenuform" width="10%">$ </td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 1000000" id="accmon" name="accmon" required style="width:80%;">
                          
                      </td>
                      
                 </tr>
                   <tr>
                      <td class="textotablamenuform"  width="10%">Accionista 2</td>
                      <td class="textotablamenuform" colspan="2"  width="50%">
                          <input type="text" class="campo_form" autocomplete="on"  id="accdni1" name="accdni1"  style="width:80%;">
               
                      </td>
                      <td class="textotablamenuform" width="10%">%</td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 10" id="accpor1" name="accpor1"  style="width:80%;">
                          
                      </td>
                      <td class="textotablamenuform" width="10%">$ </td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 1000000" id="accmon1" name="accmon1"  style="width:80%;">
                          
                      </td>
                      
                 </tr>
             <tr>
                      <td class="textotablamenuform"  width="10%">Accionista 3</td>
                      <td class="textotablamenuform" colspan="2"  width="50%">
                          <input type="text" class="campo_form" autocomplete="on"  id="accdni2" name="accdni2"  style="width:80%;">
               
                      </td>
                      <td class="textotablamenuform" width="10%">%</td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 10" id="accpor2" name="accpor2"  style="width:80%;">
                          
                      </td>
                      <td class="textotablamenuform" width="10%">$ </td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 1000000" id="accmon2" name="accmon2"  style="width:80%;">
                          
                      </td>
					   </td>
                      
                      
                 </tr>
                   <tr>
                      <td class="textotablamenuform"  width="10%">Accionista 4</td>
                      <td class="textotablamenuform" colspan="2"  width="50%">
                          <input type="text" class="campo_form" autocomplete="on"  id="accdni3" name="accdni3"  style="width:80%;">
               
                      </td>
                      <td class="textotablamenuform" width="10%">%</td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 10" id="accpor3" name="accpor3"  style="width:80%;">
                          
                      </td>
                      <td class="textotablamenuform" width="10%">$ </td>
                      <td class="textotablamenuform" width="10%">
                           <input type="number" class="campo_form" autocomplete="on" placeholder="Ej. 1000000" id="accmon3" name="accmon3"  style="width:80%;">
                          
                      </td>
					  
                      
                 </tr>
				   
				   
               </table>    
           </fieldset>
		   <fieldset>
              <legend><b>Total</b></legend> 
			  <div id="total" style="text-align:center;font-size:20px;color:green;text-align:center;">
			    <b>$ 0</b>
			  </div>
		    </fieldset>
		   
           </fieldset>
           <fieldset>
              <legend><b>Observaciones</b></legend> 
	   <table  width="100%">
                 <tr>
                      <td class="textotablamenuform"></td>
                      <td class="textotablamenuform">
                          <textarea cols="95" rows="15" name="observacion" id="observacion"></textarea>
                      </td>
					  </table>
			</fieldset>		
           
           <fieldset style="text-align: right;">  
            <table style="text-align: right;">
             <tr>
                    <td class="textotablamenuform" style="text-align: right;" colspan="5">
                         <input type="reset" name="enviar" value="Limpiar"  class="boton_form"/>
                         <input name="submit" id="submit" type="submit" value="Grabar Boleto" class="boton_form"/>
                     </td>
                 </tr>
                   </table>       
           </fieldset>  
           
           
           
       </div>
   </form>
       <div class="clear"></div>
   <br>
   </div>
  <?php include "includes/pie.php"?>
  
</div>
</body>
</html>
